package com.caipos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caipos.actor.common.data.rule.RuleNode;
import com.caipos.mapper.RuleNodeMapper;
import com.caipos.service.RuleNodeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RuleNodeServiceImpl extends ServiceImpl<RuleNodeMapper, RuleNode> implements RuleNodeService {
    @Override
    public Page<RuleNode> getRuleNodePage(Page<RuleNode> page) {
        return baseMapper.selectPage(page, null);
    }

    @Override
    public List<RuleNode> findRuleNodesByRuleNode(RuleNode ruleNode) {
        QueryWrapper<RuleNode> queryWrapper = new QueryWrapper<>();
        if (ruleNode.getId() != null) {
            queryWrapper.eq("id", ruleNode.getId());
        }
        if (ruleNode.getRuleChainId() != null) {
            queryWrapper.eq("rule_chain_id", ruleNode.getRuleChainId());
        }
        if (ruleNode.getType() != null) {
            queryWrapper.eq("type", ruleNode.getType());
        }
        if (ruleNode.getName() != null) {
            queryWrapper.eq("name", ruleNode.getName());
        }
        if (ruleNode.getSingletonMode() != null) {
            queryWrapper.eq("singleton_mode", ruleNode.getSingletonMode());
        }
        if (ruleNode.getQueueName() != null) {
            queryWrapper.eq("queue_name", ruleNode.getQueueName());
        }
        if (ruleNode.getExternalId() != null) {
            queryWrapper.eq("external_id", ruleNode.getExternalId());
        }
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public RuleNode findRuleNodeById(String id) {
        return baseMapper.selectById(id);
    }
}    